// 遍历Table的函数
function AccessALLTable(objTab)
{
  for (var i = 0; i < objTab.rows.length; i++)
  {
    for (var j = 0; j < objTab.rows[i].cells.length; j++)
    {
      s = objTab.rows[i].cells[j].outerHTML;
      alert("第" + i + "行，第" + j + "列：outerHTML为  " + s);
      s = objTab.rows[i].cells[j].innerHTML;
      alert("第" + i + "行，第" + j + "列：innerHTML为  " + s);
    }
  }
}

// Str - TD的定义字符串
// Prop - 属性值，可以是colspan、rowspan、border、width等数值型属性的名称
// 返回值是属性的值
// 例如TD的定义为<td width=100>xx</td>
// 则getPropValue("td width=100>xx</td>", "width")返回100
function getIntPropValue(Str, Prop)
{
  var s = Str.toUpperCase(Str);
  var p = Prop.toUpperCase(Prop);
  var idx = s.indexOf(p);
  var PropValue = "";
  if (idx >= 0)
  {
    var x = Prop.length;
    while ((Str.charAt(idx + x) < "0") || (Str.charAt(idx + x) > "9"))
    {
      x++;
    }
    while ((Str.charAt(idx + x) >= "0") && (Str.charAt(idx + x) <= "9"))
    {
      PropValue = PropValue + Str.charAt(idx + x);
      x++;
    }
    return PropValue;
  }
  else
    return "";
}

// 增强型的导出HTML的Table到Excel
function PrintTableToExcelEx(objTab)
{
  try 
  {
    var xls = new ActiveXObject( "Excel.Application" );
  }
  catch(e) 
  {
    alert( "要打印该表，您必须安装Excel电子表格软件，同时浏览器须使用“ActiveX 控件”，您的浏览器须允许执行控件。 请点击【帮助】了解浏览器设置方法！");
    return false;
  }
  xls.visible = true;
  var xlBook  = xls.Workbooks.Add;
  var xlsheet = xlBook.Worksheets(1);
  
  
  
  str=objTab.rows[1].cells[1].innerHTML;
  str=str.replace(/&nbsp;/g,' ');
  xlsheet.Cells(1, 1).Value='样品名称:';
  xlsheet.Cells(1, 2).Value=str;  
  
  str=objTab.rows[2].cells[1].innerHTML;
  str=str.replace(/&nbsp;/g,' ');
  xlsheet.Cells(2, 1).Value='样品批号:';
  xlsheet.Cells(2, 2).Value=str;
  
  str=objTab.rows[4].cells[1].innerHTML;
  str=str.replace(/&nbsp;/g,' ');
  xlsheet.Cells(3, 1).Value='送样人:';
  xlsheet.Cells(3, 2).Value=str;
  
  str=objTab.rows[3].cells[1].innerHTML;
  str=str.replace(/&nbsp;/g,' ');
  xlsheet.Cells(3, 3).Value='是否紧急:';
  xlsheet.Cells(3, 4).Value=str;
  
  str=objTab.rows[5].cells[1].innerHTML;
  str=str.replace(/&nbsp;/g,' ');
  xlsheet.Cells(4, 1).Value='送样日期:';
  xlsheet.Cells(4, 2).Value=str;
  
  str=objTab.rows[6].cells[1].innerHTML;
  str=str.replace(/&nbsp;/g,' ');
  xlsheet.Cells(5, 1).Value='送样时间:';
  xlsheet.Cells(5, 2).Value=str;
  
  xlsheet.Cells(1,1).Font.Size=13;  //字体大小
  xlsheet.Cells(1,2).Font.Size=20;  //字体大小
  var  R = xls.Range(xls.Cells(2, 1), xls.Cells(5, 4));  
  R.Font.Size=13;
  R = xls.Range(xls.Cells(1, 1), xls.Cells(5, 4));  
  R.Font.Bold=1;   //字体加粗
//  xlsheet.Cells(5,2).Font.Bold=1;
  
  R = xls.Range(xls.Cells(1, 2), xls.Cells(1, 4));  //合并
  R.MergeCells = true;
//  R.Borders.LineStyle = 1;
  
  R = xls.Range(xls.Cells(2, 1), xls.Cells(2, 2));  //合并
// R.MergeCells = true;
//  R.Borders.LineStyle = 1;
//R = xls.Range(xls.Cells(2, 3), xls.Cells(2, 4));  //合并
//  R.MergeCells = true;
//  R.Borders.LineStyle = 1;
// R = xls.Range(xls.Cells(3, ), xls.Cells(3, 2));  //合并
//  R.MergeCells = true;
//  R.Borders.LineStyle = 1;
//  R = xls.Range(xls.Cells(3, 3), xls.Cells(3, 4));  //合并
//  R.MergeCells = true;
//  R.Borders.LineStyle = 1;
  R = xls.Range(xls.Cells(4, 2), xls.Cells(4, 4));  //合并
  R.MergeCells = true;
//  R.Borders.LineStyle = 1;
  
/*  R = xls.Range(xls.Cells(4, 3), xls.Cells(4, 4));  //合并
  R.MergeCells = true;
  R.Borders.LineStyle = 1;
  R = xls.Range(xls.Cells(5, 1), xls.Cells(5, 2));  //合并
  R.MergeCells = true;
  R.Borders.LineStyle = 1;
  R = xls.Range(xls.Cells(5, 3), xls.Cells(5, 4));  //合并
  R.MergeCells = true;
  R.Borders.LineStyle = 1;*/

  xlsheet.Rows("1").RowHeight = 45;        //行高
  xlsheet.Rows("2:5").RowHeight = 25;        //行高

  xlsheet.Columns("A").ColumnWidth =12;     //列宽
  xlsheet.Columns("B").ColumnWidth =12;     
  xlsheet.Columns("C").ColumnWidth =12;     
  xlsheet.Columns("D").ColumnWidth =5;     

  xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(5,4)).HorizontalAlignment =-4131;

  xlsheet.PageSetup.LeftMargin= 0.7/0.035; //页边距 左2厘米 
  xlsheet.PageSetup.RightMargin = 0/0.035; //页边距右3厘米 
  xlsheet.PageSetup.TopMargin = 0.9/0.035; //页边距上4厘米 
  xlsheet.PageSetup.BottomMargin = 0/0.035; //页边距下5厘米 
  xlsheet.PageSetup.HeaderMargin = 0/0.035; //页边距页眉1厘米 
  xlsheet.PageSetup.FooterMargin = 0/0.035; //页边距页脚2厘米 

//  xlsheet.Range( xlsheet.Cells(10,1),xlsheet.Cells(10,1)).HorizontalAlignment =-4152;
  
  return;
}

//导出HTML的Table到Excel
function PrintTableToExcel(objTab)
{
  try 
  {
    var xls = new ActiveXObject( "Excel.Application" );
  }
  catch(e) 
  {
    alert( "要打印该表，您必须安装Excel电子表格软件，同时浏览器须使用“ActiveX 控件”，您的浏览器须允许执行控件。 请点击【帮助】了解浏览器设置方法！");
    return false;
  }
  xls.visible = true;
  var xlBook  = xls.Workbooks.Add;
  var xlsheet = xlBook.Worksheets(1);
  var x = 1;
  var y = 1;
  for (var i = 0; i < objTab.rows.length; i++)
  {
    y = 1;
    for (var j = 0; j < objTab.rows[i].cells.length; j++)
    {
      xlsheet.Cells(x, y).Value = objTab.rows[i].cells[j].innerHTML;
      xlsheet.Cells(x, y).Borders.LineStyle = 1;
      y++;
    }
    x++;
  }
  xlsheet.Columns.AutoFit; //自动适应大小
  return;
}